package com.ruoyi.web.controller.tool;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RecordProp;
import com.ruoyi.system.service.IRecordPropService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动态字段管理Controller
 *
 * @author admin
 * @date 2022-10-04
 */
@RestController
@RequestMapping("/tool/prop")
public class RecordPropController extends BaseController {
    @Autowired
    private IRecordPropService recordPropService;

    /**
     * 查询动态字段管理列表
    */
    @GetMapping("/list")
    public TableDataInfo list(RecordProp recordProp) {
        List<RecordProp> list = recordPropService.selectRecordPropList(recordProp);
        return getDataTable(list);
    }

    /**
     * 查询动态字段管理列表 馆藏
     */
    @PostMapping("/listbook")
    public TableDataInfo listbook(@RequestBody Map<String, Object> map) {
        List<RecordProp> list = recordPropService.selectRecordPropListBook(map);
        return getDataTable(list);
    }

    /**
     * 导出动态字段管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:prop:export')")
    @Log(title = "动态字段管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordProp recordProp) {
        List<RecordProp> list = recordPropService.selectRecordPropList(recordProp);
        ExcelUtil<RecordProp> util = new ExcelUtil<RecordProp>(RecordProp. class);
        util.exportExcel(response, list, "动态字段管理数据");
    }

    /**
     * 获取动态字段管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(recordPropService.selectRecordPropById(id));
    }

    /**
     * 新增动态字段管理
     */
    @PreAuthorize("@ss.hasPermi('system:prop:add')")
    @Log(title = "动态字段管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordProp recordProp) {
        return toAjax(recordPropService.insertRecordProp(recordProp));
    }

    /**
     * 修改动态字段管理
     */
    @PreAuthorize("@ss.hasPermi('system:prop:edit')")
    @Log(title = "动态字段管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordProp recordProp) {
        return toAjax(recordPropService.updateRecordProp(recordProp));
    }

    /**
     * 删除动态字段管理
     */
    @PreAuthorize("@ss.hasPermi('system:prop:remove')")
    @Log(title = "动态字段管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(recordPropService.deleteRecordPropById(id));
    }
}
